package com.loginlib.table.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.loginlib.table.view.TablePageView;


/**
 * Created by Administrator on 2016/7/25.
 */
public class TablePageViewAdapter extends PagerAdapter {

    private final Context mContext;

    public TablePageViewAdapter(Context context){
        this.mContext = context;
    }
    private int count;

    public void setCount(int count) {
        this.count = count;
        notifyDataSetChanged();
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    @Override
    public int getCount() {
        return count;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        // TODO: 2016/7/25 新建桌面布局
        Log.d("TablePageViewAdapter","instantiateItem="+position);
        TablePageView pageView = new TablePageView(mContext);
        pageView.setPageID(position + 1);
        container.addView(pageView);
        return pageView;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // TODO Auto-generated method stub
//        super.destroyItem(container, position, object);
        ((ViewPager) container).removeView((View) object);
    }


//    @Override
//    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
//    }
}
